package common.entities.abst;


/**
 * @author Yoyo
 *
 */
public abstract class AbstPersistentEntity {
	
	/**
	 * when the client wishes to create a new record, that record
	 * wouldn't have an id (because it wan't taken from the DB)
	 * - in those cases the client should use this value, that
	 * indicates that this is a new record
	 */
	public static final int newRecordID = -1;
	private int id;
	
	
	/**
	 * This constructor will be used for entities that are fetched from the DB
	 * 
	 * @param id
	 */
	public AbstPersistentEntity(int id){
		this.id = id;
	}
	
	/**
	 * This constructor will be used for new entities (i.e still weren't saved into DB)
	 */
	public AbstPersistentEntity(){
		this.id = newRecordID;
	}

	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	protected String fixEscapeCharacters(String stringToFix) {
		if (stringToFix==null) return null;
		return stringToFix.replaceAll("['\"\\\\]", "\\\\$0");
	}
	
	protected String fixEscapeCharactersReverse(String stringToFix){
		if (stringToFix==null) return null;
		stringToFix = stringToFix.replaceAll("\\\\\'", "\'");
		return stringToFix.replaceAll("\\\\\"", "\"");
	}
	
	
}
